package com.situ.staff.controller;

import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import com.situ.staff.bean.JsonResult;
import com.situ.staff.utils.UploadUtil;

@Controller
public class IndexController {

	@RequestMapping("/")
	public String index() {

		return "index";
	}

	// 文件上传

	@PostMapping("/upload")
	@ResponseBody
	public JsonResult upload(MultipartFile file, HttpServletRequest request) {

		String path = request.getServletContext().getRealPath("upload");
		String fileName = UploadUtil.save(file, path);

		JsonResult jsonResult = new JsonResult();
		jsonResult.setData(fileName);

		return jsonResult;
	}

}
